/**
 * Program   :   DictionaryServiceImpl.java
 * Author    :   shadow guo
 * Create    :   2013-6-28 下午4:40:43
 *
 * Copyright 2008 by Tongfu Information Technology Co. Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Tongfu Information Technology Co. Ltd. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Tongfu Information Technology Co. Ltd.
 * 
 */
package com.tongfusoft.example.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;

import com.tongfusoft.web.core.Constant;
import com.tongfusoft.web.core.data.DictionaryData;
import com.tongfusoft.web.core.service.IDictionaryService;
import com.tongfusoft.web.utils.ParameterUtils;

public class DictionaryServiceImpl implements IDictionaryService {

	@Override
	public Map<String, String> getDictByCode(String dictCode) {
		Map<String,String> result = new HashMap<String,String>();
		
		Map<String, Object> appMap = ServletActionContext.getContext()
				.getApplication();
		String currProject = ParameterUtils.getCurrProjectId();

		List<DictionaryData> dicts = ParameterUtils
				.findDictionaryByCode(
						(Map<String, Map<String, List<DictionaryData>>>) appMap
								.get(Constant.DICTIONARY), dictCode,
						currProject);
		if(dicts != null ){
			for(DictionaryData dictData : dicts){
				result.put(dictData.getDictionaryValue(), dictData.getDisplayName());
			}
		}

		return result;
	}

	@Override
	public Map<String, Map<String, String>> getDictByCode(List<String> dictCodes) {
		Map<String, Map<String, String>> result = new HashMap<String, Map<String, String>>();
		
		for(String dictCode : dictCodes){
			result.put(dictCode, getDictByCode(dictCode));
		}
		
		return result;
	}

}
